package main


import (
    "fmt"
    "io/ioutil"
)


func HashMap() {
    s := map[int]string {
        1 : "one",
        2 : "two",
        3 : "three",
    }
    fmt.Println(s)
    for k, v := range s{
        fmt.Println(k, v)
    }
    
    number := s[1]
    fmt.Println(number)
}


func readFile(filename string) {
    contents, _ := ioutil.ReadFile(filename)
    fmt.Println(contents)
    fmt.Printf("%s \n", contents)
    fmt.Printf("%d \n", contents)
}


func readAndOpenFile() {
    const filename = "123.txt"  
    readFile(filename)
}


type treeNode struct {
    value int
    left, right *treeNode
}


func createTreeNode(Value int) *treeNode {
    return &treeNode{value: Value}
}


func (node treeNode) print() {
    fmt.Printf("%d ", node.value)
}


func (node * treeNode) traverse() {
    if node == nil {
        return 
    }
    
    node.left.traverse()
    node.print()
    node.right.traverse()
}


func (node * treeNode) setValue(Value int) {
    if node == nil {
        return
    }

    node.value = Value
}


func treeNodeTraver() {
    var root treeNode

    root = treeNode{value: 1}
    root.right = createTreeNode(3)    
    root.left = createTreeNode(2)    


    root.left.left = createTreeNode(4)    
    root.left.right = createTreeNode(5)    

    root.right.left = createTreeNode(6)    
    root.right.right = createTreeNode(7)    

    root.traverse()
}


func main(){
    HashMap()
    fmt.Println()
    readAndOpenFile()
    fmt.Println()
    fmt.Println("后序遍历结果")
    treeNodeTraver()
    fmt.Println()
}



